package com.mt.api.util;

import com.mt.api.constants.enums.SizeSortNumEnum;
import com.mt.api.modules.domain.AppSku;
import com.mt.api.modules.domain.vo.AppInstoreVo;
import com.mt.api.modules.domain.vo.StockCargoRecordVo;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: plover
 * @Date: 2022/01/04 4:40 下午
 * @Description:
 */
public class ColorSizeSortUtil {

    /**
     * sku根据颜色尺码排序
     * @param skuList
     * @return
     */
    public static List<AppSku> skuSort(List<AppSku> skuList){
        Comparator<AppSku> comparator = Comparator.comparing(AppSku::getColor)
                .thenComparing(appSku -> SizeSortNumEnum.sortNumOfName(appSku.getSize()));
        return skuList.stream().sorted(comparator).collect(Collectors.toList());
    }

    /**
     * 库存数据排序
     * @param stockRecordList
     * @return
     */
    public static List<StockCargoRecordVo.StockRecord> stockSort(List<StockCargoRecordVo.StockRecord> stockRecordList){
        Comparator<StockCargoRecordVo.StockRecord> comparator = Comparator.comparing(StockCargoRecordVo.StockRecord::getColor)
                .thenComparing(stockRecord -> SizeSortNumEnum.sortNumOfName(stockRecord.getSize()));
        return stockRecordList.stream().sorted(comparator).collect(Collectors.toList());
    }

    /**
     * 入库数据排序
     * @param instoreDetailVoList
     * @return
     */
    public static List<AppInstoreVo.InstoreDetailVo> instoreSort(List<AppInstoreVo.InstoreDetailVo> instoreDetailVoList){
        Comparator<AppInstoreVo.InstoreDetailVo> comparator = Comparator.comparing(AppInstoreVo.InstoreDetailVo::getColor)
                .thenComparing(stockRecord -> SizeSortNumEnum.sortNumOfName(stockRecord.getSize()));
        return instoreDetailVoList.stream().sorted(comparator).collect(Collectors.toList());
    }
}
